package it.univaq.mancoosi.injectors.systemconfiguration.managers;


import it.univaq.mancoosi.injectors.systemconfiguration.managers.ubuntu.UbuntuEnvironmentManager;
import it.univaq.mancoosi.mancoosimm.Alternative;
import it.univaq.mancoosi.mancoosimm.MancoosiFactory;

import java.util.HashMap;
import java.util.Iterator;

public abstract class AlternativesManager {
	protected static AlternativesManager INSTANCE ;
	protected MancoosiFactory factory;
	protected HashMap<String, Alternative> alternativeMap; 

	// Private constructor prevents instantiation from other classes
	protected  AlternativesManager() {
		factory = MancoosiFactory.eINSTANCE; 
		INSTANCE = this;
		this.alternativeMap = new HashMap<String, Alternative>();
	}

	public static AlternativesManager getInstance() {
		return INSTANCE;
	}

	public abstract Alternative getAlternative(String alternativeName);

	public abstract Boolean exists(String alternativeName);

	public abstract void createAlternativesFromSystem();

	public abstract void synchronize();

	protected void syncMap () {
		try {
			Iterator<Alternative> iterator = UbuntuEnvironmentManager.getInstance().getEnvironment().getAlternatives().iterator();
			while (iterator.hasNext()) {
				Alternative curr = iterator.next();
				this.alternativeMap.put(curr.getName(), curr);
			}
		}
		catch (NullPointerException e) {
			e.printStackTrace();
		}
	}

}
